import { Model, DataTypes } from "sequelize";
import { connectSQLite } from "../sqlite";
import type { Sequelize } from "sequelize";

const sequelize: Sequelize = connectSQLite();

class User extends Model {
  id: number | undefined;
  name: string | undefined;
  firstName: string | undefined;
  lastName: string | undefined;
  email: string | undefined;
  // staffStatus: boolean = false
  // isActived: boolean = false
}

User.init(
  {
    // 模型属性在这里定义
    id: {
      type: DataTypes.INTEGER,
      autoIncrement: true,
      primaryKey: true,
    },
    name: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    email: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    firstName: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    lastName: {
      type: DataTypes.STRING,
      // allowNull默认为true
    },
  },
  {
    // 其他模型选项放在这里
    sequelize: sequelize, // 我们需要传递连接实例
    modelName: "User", // 模型的名称在数据迁移的时候也会用到
  }
);

export { sequelize, User };
